from functools import reduce
from turtle import pensize

def f(x):
    return x*x

r = map(f,[1,2,3,4,5,6,7,8,9])
print(list(r))

def fn(x,y):
    return x*10+y

print(reduce(fn,[1,2,3,4,5]))

def is_odd(x):
    return x&1 ==0

print(list(filter(is_odd,[1,2,3,4,5,6,7,8])))

print(sorted([36,5,-12,9,-21]))
print(sorted([36,5,-12,9,-21],reverse=True))
print(sorted([36,5,-12,9,-21],key=abs))

print(list(map(lambda x: x * x, [1, 2, 3, 4, 5, 6, 7, 8, 9])))

import functools

def log(func):
    @functools.wraps(func)
    def wrapper(*args, **kw):
        print('call %s():' % func.__name__)
        return func(*args,**kw)
    return wrapper

def logtext(text):
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args,**kw):
            print('%s %s():' % (text,func.__name__))
            return func(*args,**kw)
        return wrapper
    return decorator

@log
def now():
    print('2021--9-01')

@logtext('logtext')
def nowtext():
    print('2021--9-01')

print(now())
print(nowtext())

print(int('110011',base=2))

def in2(x,base=2):
    return int(x,base)

from email.mime import base
import functools
int2=functools.partial(int,base=2)

print(in2('011110'))